<template>
	<view class="detail-container">
		<view class="item-message" :class="[userMessages.fromUser.userId == item.fromId ? 'flexEnd' : '']"
			v-for="(item,index) in userMessages.messages">
			<view class="to-user" v-if="userMessages.toUser.userId == item.fromId">
				<image :src="userMessages.toUser.avatar" mode="aspectFill">
				</image>
			</view>
			<text class="message-content">
				{{item.content}}
			</text>
			<view class="from-user" v-if="userMessages.fromUser.userId == item.fromId">
				<image :src="userMessages.fromUser.avatar" mode="aspectFill">
				</image>
			</view>
		</view>
		<view class="input-bottom">
			<textarea maxlength="200" class="text" focus="true" auto-height="true" placeholder="发消息..."></textarea>
			<uni-icons type="paperplane-filled" size="30"></uni-icons>
		</view>
	</view>
</template>

<script>
	import {
		queryMessageByFromToUserId
	} from '@/api/im/messsage.js'
	import config from '@/config'

	export default {
		data() {
			return {
				userId: '',
				param: {},
				userMessages: {},
			}
		},
		onLoad(event) {
			this.userId = event.userId;
			this.queryMessage()
		},
		methods: {
			queryMessage() {
				var that = this;
				queryMessageByFromToUserId(this.userId).then(response => {
					console.log(response);
					if (!response.toUser.avatar) {
						response.toUser.avatar =
							'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201912%2F25%2F20191225224833_zloky.thumb.400_0.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1712246351&t=cad0fe94ebb387852bfff79b193399c3'
					} else {
						response.toUser.avatar = config.baseUrl + response.toUser.avatar
					}

					if (!response.fromUser.avatar) {
						response.fromUser.avatar =
							'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fitem%2F201912%2F25%2F20191225224833_zloky.thumb.400_0.jpg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1712246351&t=cad0fe94ebb387852bfff79b193399c3'
					} else {
						response.fromUser.avatar = config.baseUrl + response.fromUser.avatar
					}
					console.log("===============================");
					console.log(response);
					that.userMessages = response;
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f8f8;
	}

	.detail-container {
		margin-bottom: 100rpx;
		margin-top: 30rpx;

		.item-message {
			display: flex;
			margin: 20px 0;

			.from-user {
				width: 38px;
				height: 38px;
				margin: 0 20px;
			}

			.to-user {
				width: 38px;
				height: 38px;
				margin: 0 20px;
			}

			.message-content {
				max-width: 220px;
				/* background-color: blue; */
				border: dashed blue 1px;
				color: black;
				border-radius: 20px;
				padding: 10px 10px
			}

			image {
				width: 38px;
				height: 38px;
			}
		}

		.flexEnd {
			justify-content: flex-end;
			.message-content {
				background: blue;
				color: white;
			}
		}

		.input-bottom {
			position: fixed;
			bottom: 0px;
			margin: 20px;
			padding: 10px;
			border-radius: 30px;
			border: solid #80808026 1px;
			width: calc(100% - 40px);
			display: flex;

			textarea {
				max-height: 60px;
				width: 100%;
				line-height: 30px;
				font-size: 15px;
				overflow: hidden;
			}

			.uni-icons {
				color: blue !important;
			}
		}
	}
</style>